import {request} from "@/network/request";
//以下为获取二维码有关的API
// 获取二维码的key
function getQRCodeKey() {
    return request({
        url: '/login/qr/key'
    })
}

// 生成二维码
export function getQr() {
    return request({
        method: 'get',
        url: `/login/qr/create?key=${
            getQRCodeKey().then((res) => {
                console.log(res)
                res.data.unikey
            }).catch((err) => {
                this.$message.error('获取验证码出错啦！')
                return err
            })}&qrimg=66`
    })
}

//轮询二维码状态接口
export function polling() {
    return request({
        method: 'get',
        url: `/login/qr/check?key=${
            getQRCodeKey().then((res) => {
                res.data.unikey
            }).catch((err) => {
                return err
            })}`
    })
}

//发送验证码
export function getPhoneVerificationCode(ph) {
    console.log(ph)

    return request({
        method: 'POST',
        url: '/captcha/sent',
        params: {
            phone: ph
        }
    })
}


//验证验证码
export function VerificationCode(ph, ver) {
    return request({
        url: '/captcha/verify',
        params: {
            phone: ph,
            captcha: ver,
        }
    })
}


//用户手机号登陆,密码和验证码可选
export function loginPh(ph, md5_pw) {
    return request({
        method: 'get',
        url: `/login/cellphone`,
        params: {
            phone: ph,
            // password: pw,
            md5_password: md5_pw
        }
    })
}

//邮箱登陆
export function emailLogin(email, md5_pw) {
    return request({
        method: 'get',
        url: '/login',
        params: {
            email: email,
            md5_password: md5_pw
        }
    })
}

//刷新用户的登陆状态
export function refreshLoginStatus() {
    return request({
        url: '/login/refresh'
    })
}

// 获取用户信息
export function getUserInfo(id) {
    return request({
        url: `/user/detail?uid=${id}`,

    })
}

// 退出登录
export function getQuit() {
    return request({
        url: `/logout`,

    })
}

